package pub.gll.onepeas.libbase.track.holder

import androidx.collection.ArrayMap
import pub.gll.onepeas.libbase.track.model.ExposureInner
import pub.gll.onepeas.libbase.track.util.ExposureDataManager
import pub.gll.onepeas.libbase.track.model.ExposureModel

/**
 * <pre>
 *     author : whg
 *     e-mail : guanhuawei@kkworld.com
 *     time   : 2021/06/24
 *     version: 1.0
 * </pre>
 */
class InVisibleExposureHolder : ExposureHolder {


    override fun exposureWindowChange(exposureInner: ExposureInner) {
        var exposureMap: MutableMap<Any, ExposureModel> = ArrayMap()
        exposureInner.lastVisibleViewMap?.let { exposureMap.putAll(it) }
        //曝光需要曝光的view
        for (controlName in exposureMap.keys) {
            exposureMap[controlName]?.let {
                //上报
                ExposureDataManager.onViewInVisible(it)

            }
        }
    }

    /**
     * 从可见到不可见：
     *   当前的作为下一次上报的view，曝光上次不可见的
     * @param exposureInner ExposureInner
     */
    override fun exposureViewChange(exposureInner: ExposureInner) {
        var current: MutableMap<Any, ExposureModel> = ArrayMap()
        var last: MutableMap<Any, ExposureModel> = ArrayMap()
        exposureInner.currentVisibleViewMap?.let { last.putAll(it) }
        exposureInner.lastVisibleViewMap?.let { current.putAll(it) }

        for (controlName in current.keys) {
            if (!last.containsKey(controlName)) {
                current[controlName]?.let {
                    ExposureDataManager.onViewInVisible(it)
                }
            }
        }
    }


}